<template>
  <div>
    <!-- 供应商信息维护 -->
    <BreakSpace label="基本信息" :containerStyle="{ marginBottom: '10px' }" />
    <FormPanel ref="formPanel" :list="formList" :cols="3" :formType="'add'" labelWidth="110" :isSubmitBtn="false"
      @formChange="formChangeHandle" />
    <div style="padding-top: 3rem;"></div>
    <div :style="{
      position: 'absolute',
      left: 0,
      right: 0,
      zIndex: 9,
      borderTop: '1px solid #e9e9e9',
      padding: '10px 20px',
      background: '#fff',
      textAlign: 'right'
    }">
      <multiuse-button type="primary" :click="saveDialog">保 存</multiuse-button>
      <multiuse-button type="primary" @click="closeDialog">关 闭</multiuse-button>
    </div>
  </div>
</template>
<script>

import { editSave } from '@/api/repair/repairBusiness/supplierInformation';
import { dictionary } from '@/utils/dictMixin';
export default {
  props: ['rowData', 'userId'],
  mixins: [dictionary],
  components: {
  },
  data() {
    return {
      dataList: [],
      collapse: false,
      fetchParams: {}, //ipa 接口
      selectedRows: [], //选中服务站
      formList: this.createFormList(),
      // saveData: null,
      mrId: null,
    };
  },
  created() {
    this.formList.forEach(x => {
      x.initialValue = this.rowData[x.fieldName];
    });
  },

  methods: {
    formChangeHandle(val) {
      console.log('val', val);
      //this.saveData = val;
    },
    //保存
    async saveDialog() {
      let [err, data] = await this.$refs.formPanel.GET_FORM_DATA();
      if (err) return;
      console.log('1111', data);
      if (data.manageRate < 0 || data.manageRate > 100) {
        this.$notify.error({ title: '提示信息', message: '供应商管理费率数据校验不通过' });
        return
      }
      data = Object.assign({}, data, { mrId: this.rowData.mrId }, { userId: (this.userId) })
      let save = JSON.parse(JSON.stringify(data))
      let res = await editSave(save);
      if (res.resultCode === 200) {
        this.loading = false;
        this.$notify.success({ title: '提示信息', message: '保存成功!' });
        this.$emit('close', { visibleEdit: false, data: this.selectedRows, type: 'save' });
      } else {
        this.loading = false;
        //this.$notify.error({ title: '提示信息', message: '保存失败!' });
      }
    },
    //取消操作
    closeDialog() {
      this.$emit('close', { visibleEdit: false, data: null, type: 'close' });
    },
    //回运单信息
    createFormList() {
      return [
        {
          type: 'INPUT',
          label: '供应商代码',
          fieldName: 'supplierCode',
          initialValue: '',
          disabled: true, // 置会
          readonly: true,// 只读
          rules: [{ required: true, message: '请选择供应商代码', trigger: 'change' }]
        },
        {
          type: 'INPUT',
          label: '供应商名称',
          fieldName: 'supplierName',
          initialValue: '',
          disabled: true, // 置会
          readonly: true, // 只读
          rules: [{ required: true, message: '请选择供应商名称', trigger: 'change' }]
        },
        {
          type: 'SELECT',
          label: '供应商类型',
          fieldName: 'isInterior',
          initialValue: '',
          itemList: [
            { text: '内部', value: 10041001 },
            { text: '外部', value: 10041002 }
          ],
          rules: [{ required: true, message: '请选择供应商类型', trigger: 'change' }]
        },
        {
          type: 'INPUT',
          label: '供应商工时单价',
          fieldName: 'hourPrice',
          initialValue: '',
          rules: [{ required: true, message: '请输入供应商工时单价', trigger: 'change' }, { pattern: /^(\d+)(\.?)(\d{0,2})$/, message: '请输入数字值,小数点后两位...', trigger: 'blur' }]
        },
        {
          type: 'INPUT',
          label: '供应商管理费率',
          fieldName: 'manageRate',
          initialValue: '',
          placeholder: '请输入供应商管理费率...',
          rules: [{ required: true, message: '请输入供应商管理费率...', trigger: 'blur' }, { pattern: /^(\d+)(\.?)(\d{0,2})$/, message: '请输入数字值,小数点后两位...', trigger: 'blur' }],
          unitRender: () => {
            return <span>(%)</span>;
          },
        },
        {
          type: 'INPUT',
          label: 'K系数',
          fieldName: 'krate',
          precision: 2,
          rules: [{ required: true, message: '请输入K系数', trigger: 'change' }, { pattern: /^(\d+)(\.?)(\d{0,2})$/, message: '请输入数字值,小数点后两位...', trigger: 'blur' }]
        },
      ];
    },
  }
}
  ;
</script>
<style lang="less" scoped>

</style>
